package com.hongminzheng.openapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongminzheng.openapi.mapper.CustomerMapper;
import com.hongminzheng.openapi.pojo.Application;
import com.hongminzheng.openapi.pojo.Customer;
import com.hongminzheng.openapi.service.CustomerService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hmz
 * @version v1.0
 * @data 2020/09/27
 **/
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    CustomerMapper customerMapper;

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return customerMapper.deleteByPrimaryKey(id);
    }

    /**
     * 增加
     * @param customer
     * @return
     */
    @Override
    public int insert(Customer customer) {
        return customerMapper.insert(customer);
    }

    @Override
    public int insertSelective(Customer customer) {
        return customerMapper.insertSelective(customer);
    }

    @Override
    public Customer selectByPrimaryKey(Integer id) {
        return customerMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Customer customer) {
        return customerMapper.updateByPrimaryKeySelective(customer);
    }

    /**
     * 更新
     * @param customer
     * @return
     */
    @Override
    public int updateByPrimaryKey(Customer customer) {
        return customerMapper.updateByPrimaryKey(customer);
    }


    /**
     * 分页查找
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Customer> findPage(Integer pageNum, Integer pageSize, Customer customer) {
        PageHelper.startPage(pageNum, pageSize);
        List<Customer> customers = customerMapper.findByUsernameAndState(customer);
        PageInfo<Customer> pageInfo = new PageInfo<>(customers);
        return pageInfo;
    }


}
